home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / VGAFX.ZIP / DEMO1.ASM < prev    next >
Assembly Source File  |  1989-10-09  |  18KB  |  589 lines

  1. Comment *
  2.  
  3.         Purpose:
  4.             demos "flashing" text under attribute control mode 0.
  5.  
  6.         Required external modules:
  7.             flash0.obj
  8.  
  9.         Prep:
  10.             masm demo0;     (tested under MASM 5.1, OPTASM 1.5)
  11.             link demo0+flash0;
  12.             exe2bin demo0 demo0.com
  13.  
  14.         Run:
  15.             demo0
  16.  
  17.         Copyright:
  18.             none
  19.  
  20.         Author:
  21.             C.J. Dunford [CompuServe 76703,2002]
  22.             301/992-9371
  23.  
  24.         Revision history:
  25.             1.00 10/03/89
  26.  
  27. *
  28.  
  29.  
  30. code segment word public 'code'
  31. assume cs:code,ds:code,es:code
  32.  
  33. extrn flash_init:near,flash_term:near
  34. extrn pulse_color:near,pulse_color_partial:near
  35. extrn grade_color_partial:near,grade_color:near
  36. extrn blinker:near
  37. extrn load_palettes:near,reset_palettes:near
  38. extrn set_color:near,set_color_partial:near
  39. extrn set_flash_rate:near,set_delta:near
  40. extrn flash_enabled:byte
  41.  
  42. org 100h
  43.  
  44. ; ===================================================================
  45. ;                                MAINLINE CODE
  46. ; ===================================================================
  47.  
  48. demo0:
  49. ; Initialize the VGA for controlled flashing
  50.         call flash_init
  51.         jnc demo1                       ; NC = VGA OK
  52.             mov dx,offset no_VGA$       ; No VGA, terminate with message
  53.             mov ah,9
  54.             int 21h
  55.             mov ax,4C01h
  56.             int 21h
  57.  
  58. ; Pulse reds and greens by slowly augmenting color intensity
  59. demo1:
  60.         mov ax,0202H                    ; AL=color 2 (green), AH=2 (incr/pal)
  61.         call pulse_color                ; Create pulsed attribute
  62.         mov ax,0204H                    ; AL=color 4 (red)
  63.         call pulse_color
  64.         mov ax,020AH                    ; AL=color 10 (brt green)
  65.         call pulse_color
  66.         mov ax,020CH                    ; AL=color 12 (brt red)
  67.         call pulse_color                ; Create pulsed attribute
  68.         call load_palettes              ; Load new palettes into VGA
  69.                                         ; After this call, anything red or
  70.                                         ; green will flash.  Nothing to it.
  71.         mov si,offset rg_aug$           ; Display the demo
  72.         call scrn
  73.  
  74. ; Pulse all 16 attributes, using the same augmented intensity effect
  75.         mov cx,16                       ; 16 attributes
  76.         mov ax,0200H                    ; Start with attr 0
  77. p16:        push ax
  78.             call pulse_color
  79.             pop ax
  80.             inc al                      ; Next attribute
  81.             loop p16
  82.         call load_palettes
  83.         mov si,offset all_aug$
  84.         call scrn
  85.  
  86. ; Instant color change: green to bright red
  87.         call reset_palettes             ; Clear all special effects
  88.         mov al,2
  89.         mov si,offset max_red
  90.         mov cx,0F08h
  91.         call set_color_partial
  92.         call load_palettes
  93.         mov si,offset g2R$              ; Display the demo
  94.         call scrn
  95.  
  96. ; Graded color change: green to bright red
  97.         call reset_palettes             ; Clear all special effects
  98.         mov al,2
  99.         mov si,offset max_red
  100.         call grade_color
  101.         call load_palettes
  102.         mov si,offset grd_g2R$          ; Display the demo
  103.         call scrn
  104.  
  105. ; Blink red to bright red--periodic intensification
  106.         call reset_palettes
  107.         mov al,2
  108.         call set_delta
  109.         mov al,0C4H                     ; Set up blinking on bright red
  110.         call blinker
  111.         call load_palettes
  112.         mov si,offset r2R$              ; Display the demo
  113.         call scrn
  114.  
  115. ; Demo simulated 'real' flashing
  116.         call reset_palettes             ; Reset the green/red flashing
  117.         mov al,2                        ; Flash a little faster
  118.         call set_delta
  119.         mov al,12                       ; Set up blinking on bright red
  120.         call blinker
  121.         call load_palettes
  122.         mov si,offset flash$            ; Display the demo
  123.         call scrn
  124.  
  125. ; Demonstrate "softened blinking": instead of just blinking
  126. ; on and off, we reduce the intensity of the color in palettes 0-7
  127. ; and then set 8-15 to the BG color (black, in this case)
  128.         call reset_palettes             ; Clear all special effect
  129.         mov al,3                        ; Cyan attribute
  130.         mov si,offset black
  131.         mov cl,0
  132.         mov ch,8
  133.         call grade_color_partial        ; Grade cyan to black in 0->7
  134.         mov al,3                        ; Black BG, cyan FG
  135.         call blinker                    ; Makes cyan black in 8-15
  136.         call load_palettes
  137.         mov si,offset soft$
  138.         call scrn
  139.  
  140. ; Demo 'fading'.  Just grade the color to black (or whatever BG)
  141.         call reset_palettes
  142.         mov al,3
  143.         mov si,offset black
  144.         call grade_color
  145.         call load_palettes
  146.         mov si,offset fade$
  147.         call scrn
  148.  
  149. ; Demo "strobe" and "beacon" effects
  150.         call reset_palettes
  151.         mov al,1
  152.         call set_delta
  153.         mov al,14                       ; Set attr 14 to black, pals 0-14
  154.         mov si,offset black
  155.         mov cx,0E00h
  156.         call set_color_partial          ; And to bright yellow for pal 15
  157.         mov al,14
  158.         mov si,offset max_yellow
  159.         mov cx,0F0FH
  160.         call set_color_partial
  161.  
  162.         mov al,1                        ; Set blue to max blue in pal 15
  163.         mov si,offset max_blue
  164.         mov cx,0F0FH
  165.         call set_color_partial
  166.         call load_palettes
  167.         mov si,offset strobe$
  168.         call scrn
  169.  
  170. ; Demonstrate that the blink rate can be adjusted.  We make
  171. ; green and bright red flash bright green, very fast (~18/sec).
  172. ; The red/green flash is particularly psychedelic.
  173.         call reset_palettes
  174.         mov al,2
  175.         mov si,offset max_grn
  176.         call grade_color
  177.         mov al,12
  178.         mov si,offset max_grn
  179.         call grade_color
  180.         call load_palettes
  181.         mov al,15
  182.         call set_delta
  183.         mov si,offset fast$
  184.         call scrn
  185.  
  186. ; ...and then very slowly.
  187.         mov al,1
  188.         call set_delta
  189.         mov ax,9
  190.         call set_flash_rate
  191.         mov si,offset slow$
  192.         call scrn
  193.         mov ax,1
  194.         call set_flash_rate
  195.         mov al,2
  196.         call set_delta
  197.  
  198. ; Show that all this can be done with BG colors too.  We'll set blue
  199. ; to flash to bright blue and use it as a background.  Just for grins,
  200. ; we'll set attribute 2 (green) to display as blue, to show that you can
  201. ; have a plain blue and a flashing blue on the same screen (but there
  202. ; won't be any green).
  203.         call reset_palettes
  204.         mov al,1
  205.         mov si,offset max_blue
  206.         mov cx,0F08h
  207.         call set_color_partial
  208.         mov al,2
  209.         mov si,offset blue
  210.         call set_color
  211.         call load_palettes
  212.         mov si,offset back$
  213.         mov al,20h
  214.         call scrn9
  215.  
  216. ; Demo shows that we can use bright backgrounds but still flash.
  217. ; We CLS with a bright BG, then flash cyan text to light cyan
  218.         call hw_blink_off               ; Disable hardware blinking
  219.         call reset_palettes
  220.         mov al,93H                      ; Brt blue BG, cyan FG
  221.         call blinker
  222.         call load_palettes
  223.         mov si,offset brightback$
  224.         mov al,90h                      ; CLS with attrib 90 (bright blue)
  225.         call scrn9
  226.         call hw_blink_on                ; Re-enable hardware blink
  227.  
  228. ; The grand finale.  Show that all effects can be mixed on one screen.
  229. finale:
  230.         mov al,1
  231.         call set_delta
  232.  
  233.         ; "Beacon" in 1
  234.         mov al,1                        ; Set blue to max blue in pal 15
  235.         mov si,offset max_blue
  236.         mov cx,0F0FH
  237.         call set_color_partial
  238.  
  239.         ; Quick shift green to red in 2
  240.         mov al,2
  241.         mov si,offset max_red
  242.         mov cx,0F08h
  243.         call set_color_partial
  244.  
  245.         ; Graded green-to-red on attribute 3
  246.         mov al,3                        ; Make attr 3 base green
  247.         mov si,offset green
  248.         call set_color
  249.         mov al,3
  250.         mov si,offset max_red
  251.         call grade_color
  252.  
  253.         ; Blink red to bright red (periodic intensification) in 4
  254.         mov al,0C4H                     ; Set up blinking on bright red
  255.         call blinker
  256.  
  257.         ; Flash 5 on an off
  258.         mov al,5
  259.         call blinker
  260.  
  261.         ; "Softened blinking" in 6
  262.         mov al,6
  263.         mov si,offset black
  264.         mov cx,0800h
  265.         call grade_color_partial
  266.         mov al,6
  267.         call blinker
  268.  
  269.         ; "Fading" in 7
  270.         mov al,7
  271.         mov si,offset black
  272.         call grade_color
  273.  
  274.         ; "Pulse" in 10
  275.         mov al,10
  276.         mov si,offset green
  277.         call set_color
  278.         mov ax,020AH
  279.         mov cx,0F00H
  280.         call pulse_color
  281.  
  282.         ; Blacken every other palette in 11 (we haven't seen this one yet)
  283.         mov si,offset black
  284.         mov cx,0000
  285. GF10:       mov al,11
  286.             call set_color_partial
  287.             add cx,0202h
  288.             cmp ch,0FH
  289.             jbe GF10
  290.  
  291.         ; "Strobe" in 14
  292.         mov al,14
  293.         mov si,offset black
  294.         mov cx,0E00h
  295.         call set_color_partial
  296.         mov al,14
  297.         mov si,offset max_yellow
  298.         mov cx,0F0FH
  299.         call set_color_partial
  300.  
  301.         ; Load all those into VGA and display
  302.         call load_palettes
  303.         mov si,offset mixed$            ; Display the demo
  304.         call scrn
  305.  
  306. ; Demos done, clean up for return to DOS
  307.         call flash_term
  308.  
  309. ; Exit
  310.         mov al,7
  311.         call cls
  312.         mov ax,4C00h
  313.         int 21h
  314.  
  315. ; No VGA found by flash_init, exit with message
  316. no_VGA:
  317.         mov dx,offset no_VGA$
  318.         mov ah,9
  319.         int 21h
  320.         mov ax,4C01h
  321.         int 21h
  322.  
  323. ; ----- hw_blink_off -----------------------------------------------
  324. ; Function disables hardware blink, which enables bright BG.
  325. ; AX,BX destroyed.
  326. ;
  327. hw_blink_off:
  328.         mov ax,1003h
  329.         xor bl,bl
  330.         int 10h
  331.         ret
  332.  
  333. ; ----- hw_blink_on -----------------------------------------------
  334. ; Function enables hardware blink, which disables bright BG.
  335. ; AX,BX destroyed.
  336. ;
  337. hw_blink_on:
  338.         mov ax,1003h
  339.         mov bl,1
  340.         int 10h
  341.         ret
  342.  
  343. ; ----- scrn -------------------------------------------------------------
  344. ; This function clears the screen, displays the text at DS:SI, and waits
  345. ; for a keystroke.  Note that the text is flashing in background while
  346. ; we're in BIOS, waiting for a key.  In other words, once you've set
  347. ; up flashing, all you have to do is display text with the proper attributes
  348. ; (i.e., any attribute whose colors differ between palettes 1 and 2), then
  349. ; you can go on about your business.
  350. ;
  351. ; SCRN2 is similar but doesn't display the color chart and uses a
  352. ; background color of AL
  353. ;
  354. scrn:
  355.         mov al,7                        ; CLS with attrib 7 (B/W)
  356.         call cls
  357.         call display                    ; Display text at SI
  358.         call colors                     ; Display the color chart
  359. scrn50: mov si,offset prompt            ; And the "any key" prompt
  360.         call display
  361.         mov ah,1                        ; Wait for a keystroke
  362.         int 21h
  363.         ret
  364.  
  365. scrn9:
  366.         call cls
  367.         call display                    ; Display the message
  368.         jmp scrn50
  369.  
  370. ; ========================================================================
  371. ;                           FUNCTIONS FOR DEMO ONLY
  372. ; ========================================================================
  373.  
  374.  
  375. ; ----- colors -------------------------------------------------
  376. ; This subroutine display the chart of all 16 attributes.
  377. ;
  378. show macro strings
  379.         irp s,<strings>
  380.           mov si,offset &s
  381.           call display
  382.         endm
  383. endm
  384.  
  385. colors:
  386.         show <Atr0,Atr1,Atr2,Atr3,Atr4,Atr5,Atr6,Atr7,Atr8,Atr9,AtrA,AtrB,AtrC,AtrD,AtrE,AtrF>
  387.         ret
  388.  
  389.  
  390. ; ----- display -----------------------------------------------------
  391. ; Clears the screen and displays some text with various attributes.
  392. ; Text taken from DS:SI in this format:
  393. ;    Byte   Start row
  394. ;    Byte   Start col
  395. ;    Word   Number of char/attr pairs in string
  396. ;    Words  Char/attr pairs
  397. ;
  398. display:
  399.         lodsb                           ; Get row
  400.         mov dh,al
  401.         lodsb                           ; Get col
  402.         mov dl,al
  403.         lodsw                           ; Get length
  404.         mov cx,ax
  405.         mov bh,0                        ; Display page 0
  406.         mov bp,si                       ; DS:BP -> char/attr string
  407.         mov ax,1303h                    ; Display
  408.         int 10h
  409.         ret
  410.  
  411. ; ----- cls ---------------------------------------------------------
  412. ; Clear the screen, attribute 7 (normally white over black).
  413. ; AX,BX,CX,DX destroyed.
  414. ;
  415. cls:
  416.         push si
  417.         push ax
  418.  
  419. ; Get last row number to DH
  420.         push bp                         ; Function destroys ES:BP
  421.         push es
  422.         mov ax,1130h                    ; Char gen interface function
  423.         xor bh,bh                       ; Any valid subfn is OK
  424.         int 10h                         ; DL = last row #
  425.         pop es
  426.         pop bp
  427.         mov dh,dl
  428.  
  429. ; Get last column # to DL
  430.         mov ah,0FH                      ; Video GETMODE
  431.         int 10h
  432.         dec ah                          ; AH = last col #
  433.         mov dl,ah
  434.  
  435. ; Clear screen from (0,0) to (DH,DL)
  436.         pop ax                          ; Recover CLS attribute
  437.         mov bh,al                       ; Attribute to BH
  438.         mov cx,0                        ; From 0,0
  439.         mov ax,0700H                    ; Scroll up, clear entire window
  440.         int 10h
  441.  
  442.         pop si
  443.         ret
  444.  
  445. ; ========================================================================
  446. ;                                DATA FOR DEMO
  447. ; ========================================================================
  448.  
  449. ; These are some color definitions that we'll use for some of the demos.
  450. ; Each definition is three bytes long (one each for red, green, and blue).
  451. ; Valid values for each byte are 0-63.
  452. max_red     db 3FH,   0,   0
  453. green       db   0, 2AH,   0
  454. max_grn     db   0, 3FH,   0
  455. max_cyan    db   0, 3FH, 3FH
  456. black       db   0,   0,   0
  457. max_yellow  db 3FH, 3FH,   0
  458. blue        db   0,   0, 2AH
  459. brt_blue    db   0,   0, 33H
  460. max_blue    db   0,   0, 3FH
  461.  
  462.  
  463. ; Macro to define char/attr pairs for the demo display strings.
  464. ; Call: atext attrib,<text>
  465. atext macro attr,dat
  466.         irpc x,<dat>
  467.             db "&x",attr
  468.         endm
  469. endm
  470.  
  471. ; Text/attribute strings for the demo displays.  See DISPLAY routine.
  472. rg_aug$ label byte
  473.         db 0,0
  474.         dw rg_aug$L
  475.         atext 15,<This 'pulses' >
  476.         atext 4,<REDS>
  477.         atext 15,< and >
  478.         atext 2,<GREENS>
  479.         atext 15,<; high intensity >
  480.         atext 10,<colors>
  481.         atext 15,< pulse less dramatically>
  482. rg_aug$L equ ($-rg_aug$-4)/2
  483.  
  484. all_aug$  label byte
  485.         db 0,0
  486.         dw all_aug$L
  487.         atext 15,<This palette pulses all 16 attributes...>
  488. all_aug$L equ ($-all_aug$-4)/2
  489.  
  490. g2R$  label byte
  491.         db 0,0
  492.         dw g2r$L
  493.         atext 15,<Here we make green flash bright red...>
  494. g2R$L equ ($-g2r$-4)/2
  495.  
  496. grd_g2R$  label byte
  497.         db 0,0
  498.         dw grd_g2R$L
  499.         atext 15,<And this is a slow green-to-red 'grade'...>
  500. grd_g2R$L equ ($-grd_g2R$-4)/2
  501.  
  502. flash$ label byte
  503.         db 0,0
  504.         dw flash$L
  505.         atext 15,<We can also simulate blinking...>
  506. flash$L equ ($-flash$-4)/2
  507.  
  508. strobe$ label byte
  509.         db 0,0
  510.         dw strobe$L
  511.         atext 15,<This demonstrates strobes (E) and beacons (1)...>
  512. strobe$L equ ($-strobe$-4)/2
  513.  
  514. r2R$ label byte
  515.         db 0,0
  516.         dw r2R$L
  517.         atext 15,<Blinking by periodic intensification...>
  518. r2R$L equ ($-r2R$-4)/2
  519.  
  520. mixed$ label byte
  521.         db 0,0
  522.         dw mixed$L
  523.         atext 15,<All types of special effects can be mixed on one screen...>
  524. mixed$L equ ($-mixed$-4)/2
  525.  
  526. fast$ label byte
  527.         db 0,0
  528.         dw fast$L
  529.         atext 15,<You can make flashing very rapid...>
  530. fast$L equ ($-fast$-4)/2
  531.  
  532. slow$ label byte
  533.         db 0,0
  534.         dw slow$L
  535.         atext 15,<...or almost too slow to detect (C is obvious, but watch 2)...>
  536. slow$L equ ($-slow$-4)/2
  537.  
  538. soft$ label byte
  539.         db 0,0
  540.         dw soft$L
  541.         atext 15,<Here we demonstrate 'softened' blinking...>
  542. soft$L equ ($-soft$-4)/2
  543.  
  544. fade$ label byte
  545.         db 0,0
  546.         dw fade$L
  547.         atext 15,<And this is 'fading', which is even softer...>
  548. fade$L equ ($-fade$-4)/2
  549.  
  550. back$ label byte
  551.         db 10,16
  552.         dw back$L
  553.         atext 1EH,< All these effects work on background, too... >
  554. back$L equ ($-back$-4)/2
  555.  
  556. brightback$ label byte
  557.         db 10,0
  558.         dw brightback$L
  559.         atext 9Eh,<With hardware blink off, you can use bright BG but still >
  560.         atext 93h,<flash>
  561.         atext 9Eh,< your text>
  562. brightback$L equ ($-brightback$-4)/2
  563.  
  564. prompt label byte
  565.         db 24,0
  566.         dw promptL
  567.         atext 15,<Strike any key to continue...>
  568. promptL equ ($-prompt-4)/2
  569.  
  570. ; Macro generates the data definitions for the attribute chart
  571. a = 0   ; Start with attribute 0
  572. r = 2   ; At screen row 2
  573.         irp x,<0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F>
  574. Atr&x label byte
  575.         db r,25
  576.         dw 10
  577.         REPT 10
  578.             db "&x",a
  579.         endm
  580.         a = a+1
  581.         r = r+1
  582.         endm
  583.  
  584. ; Error message for non-VGA systems
  585. no_VGA$ db 'Sorry, flash demo requires VGA',13,10,10,'$'
  586.  
  587. code ends
  588. end demo0
  589.